package com.bhs.sansong.adapter;

import android.text.Html;
import android.text.Spanned;
import android.text.TextUtils;
import android.widget.ImageView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.bhs.sansong.R;
import com.bhs.sansong.bean.CompaniesInfo;
import com.bhs.sansong.bean.PriceBean;
import com.bumptech.glide.Glide;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.google.gson.Gson;

import java.util.List;

/**
 * 公司列表(废弃)
 */
public class LogisticsCompaniesAdapter extends BaseQuickAdapter<CompaniesInfo, BaseViewHolder> {

    private int type;//1选择公司 2找物流

    public LogisticsCompaniesAdapter(int type) {
        super(R.layout.item_collaboration);
        this.type = type;
    }

    @Override
    protected void convert(@NonNull BaseViewHolder helper, CompaniesInfo item) {
        Glide.with(mContext).load(item.getCompany_pic()).into((ImageView) helper.getView(R.id.iv_image));
        helper.setText(R.id.tv_company_name, item.getCompany_name());
        if (item.getLine_info().getStart_city() != null) {
            String start_city = item.getLine_info().getStart_city().replace("市", "");
            helper.setText(R.id.tv_start_city, start_city);
            String end_city = item.getLine_info().getEnd_city().replace("市", "");
            helper.setText(R.id.tv_end_city, end_city);
            PriceBean priceBean = new Gson().fromJson(item.getLine_info().getGeneral_price_json(), PriceBean.class);
            helper.setText(R.id.tv_offer, String.format("普运报价 %s/元吨 %s/立方", priceBean.P1, priceBean.P6));
        }
        helper.setVisible(R.id.rl_line, item.getLine_info().getStart_city() != null);
        helper.setText(R.id.tv_address, item.getAddress());
        helper.setText(R.id.tv_distance, String.format("%skm", item.getDistance()));
        helper.setGone(R.id.tv_distance, item.getDistance() > 0);
        Spanned PageView = Html.fromHtml("浏览量:<font color=\"#000000\">" + item.getVisitor_count() + "</font>");
        helper.setText(R.id.tv_page_view, PageView);
        Spanned OrderQuantity = Html.fromHtml("下单量:<font color=\"#000000\">" + item.getOrder_count() + "</font>");
        helper.setText(R.id.tv_order_quantity, OrderQuantity);
        Spanned QuantityCollection = Html.fromHtml("收藏量:<font color=\"#000000\">" + item.getCollect_count() + "</font>");
        helper.setText(R.id.tv_quantity_collection, QuantityCollection);
        helper.setText(R.id.tv_announcement, item.getPublic_notice());
        helper.setGone(R.id.tv_announcement, !TextUtils.isEmpty(item.getPublic_notice()));
        helper.setGone(R.id.ll_mode, type == 1);
        helper.setGone(R.id.ll_operation, type == 2);
        helper.setGone(R.id.ll_offer, item.getLine_info().getStart_city() != null);
        if (type == 1) {
            helper.setText(R.id.tv_number_days, String.format("约%s-%s天送达", item.getLine_info().getGeneral_day_min(), item.getLine_info().getGeneral_day_max()));
            helper.setText(R.id.tv_express, String.format("约%s-%s天送达", item.getLine_info().getFast_day_min(), item.getLine_info().getFast_day_max()));
        }else {
            helper.addOnClickListener(R.id.tv_consent,R.id.ll_contact);
        }
    }
}
